//
//  FDApplyController.m
//  FamousDoctorOnline
//
//  Created by wszyxc on 16/7/5.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

#import "FDApplyController.h"
#import <Masonry.h>
#import "FDApplyModel.h"
#import "FDApplyCell.h"
#import "FDDetailController.h"

@interface FDApplyController ()<UITableViewDataSource,UITableViewDelegate>

//数据源数组
@property (nonatomic , strong)NSArray *dataArray;

@end

@implementation FDApplyController

static NSString *const ID = @"apply";

/**懒加载数据*/
- (NSArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [FDApplyModel applyArray];
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupTableView];
}

/**tableView初始化*/
- (void)setupTableView {
    UITableView *applyView = [[UITableView alloc]init];
    applyView.dataSource = self;
    applyView.delegate = self;
    applyView.rowHeight = SCREEN_WIDTH*0.25;
    
    //删除tableView没有内容cell的线条
    applyView.tableFooterView = [[UIView alloc]init];
    
    [applyView registerClass:[FDApplyCell class] forCellReuseIdentifier:ID];
    [self.view addSubview:applyView];
    
    //约束设置
    [applyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.offset(0);
    }];
}

#pragma mark
#pragma mark 数据源代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    FDApplyCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    FDApplyModel *applyModel = self.dataArray[indexPath.row];
    
    cell.applyModel = applyModel;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

/**点击cell*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //取消cell的选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    FDDetailController *detaileController = [[FDDetailController alloc]init];
    
    FDApplyModel *applyModel = self.dataArray[indexPath.row];
    detaileController.applyModel = applyModel;
    
    [self.navigationController pushViewController:detaileController animated:YES];
}


@end
